import Request from './request.js';

const API = {
	addFree: '/app/bus/people/free/server',
	addSign: '/app/bus/people/sign/server',
	addService: '/app/bus/service/resume',
	getServiceList: '/app/bus/service/resume/list',
	getServiceDetail: '/app/bus/service/resume/',
	editService: '/app/bus/service/resume',
	deleteService: '/app/bus/service/resume/',
	getSkillList: '/app/bus/skill/cert/list',
	getSkillDetail: '/app/bus/skill/cert/',
	getServiceInfoList: '/app/bus/sevItem/getServiceList',
	getSignInfo: '/app/bus/people/sign/info',
	addServiceItem: '/app/bus/serviceItem/addItem',
	skillCertsList: '/app/bus/people/skillCerts',
	addOrEditSkillCert: '/app/bus/skill/cert/addOrEdit',
	deleteSkillCert: '/app/bus/skill/cert/delete' // DELETE 请求，需传 Query 参数 id
};

// 成为自由服务者（POST）
export const addFree = (params) => Request.post(API.addFree, {}, {
	data: params
});

// 成为签约服务者（POST）
export const addSign = (params) => Request.post(API.addSign, {}, {
	data: params
});

// 新增服务经历（POST）
export const addService = (params) => Request.post(API.addService, {}, {
	data: params
});

// 获取服务经历列表（GET）
export const getServiceList = () => Request.get(API.getServiceList);

// 获取服务经历详情（GET）
export const getServiceDetail = (params) => Request.get(`${API.getServiceDetail}${params}`);

// 修改服务经历（PUT）
export const editService = (params) => Request.put(API.editService, {}, {
	data: params
});

// 删除服务经历（GET，拼接 ID 到 URL）
export const deleteService = (params) => Request.get(`${API.deleteService}${params}`);

// 获取技能证书列表（GET）
export const getSkillList = () => Request.get(API.getSkillList);

// 获取技能证书详情（GET，拼接 ID 到 URL）
export const getSkillDetail = (params) => Request.get(`${API.getSkillDetail}${params}`);

// 服务信息（服务项列表）（GET）
export const getServiceInfoList = () => Request.get(API.getServiceInfoList);

// 获取签约信息（GET）
export const getSignInfo = () => Request.get(API.getSignInfo);

// 服务项 添加自定义标签（POST，Query 参数编码）
export const addServiceItem = (params) => {
	const encodedParams = {};
	for (const key in params) {
		if (params.hasOwnProperty(key)) {
			encodedParams[key] = encodeURIComponent(params[key]);
		}
	}
	return Request.post(API.addServiceItem, {}, {
		params: encodedParams
	});
};

// 技能证书列表（GET，可能需要参数，根据实际需求调整）
export const skillCertsList = (categoryIds) => {
	return Request.get(API.skillCertsList, {
		params: {
			categoryIds
		}
	});
};

// 新增或编辑技能证书（POST）
export const addOrEditSkillCert = (params) => Request.post(API.addOrEditSkillCert, {}, {
	data: params
});

// 删除技能证书（DELETE，Query 参数 id）
export const deleteSkillCert = (id) => {
    // 拼接?id=id到接口地址上
    const url = `${API.deleteSkillCert}?id=${id}`; 
    return Request.delete(url);
};